package activity;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.administrator.ci_edit.EditActivity;
import com.example.administrator.ci_edit.R;

import db.DBManager;

/**
 * Created by hello world on 2017/7/13.
 */

public class PoemShowActivity extends AppCompatActivity {
    //private ImageView imageView;
    private Button button;
    private TextView textView;
    private TextView nameTextView;
    @Override

    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_poem_show);
        //imageView=(ImageView)findViewById(R.id.image_view);

        Intent intent=getIntent();
        final int rsndm = intent.getIntExtra("extra_mengid",0);

        button=(Button)findViewById(R.id.writebtn);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //在这里输入要跳转的界面
                Intent intent=new Intent(PoemShowActivity.this,EditActivity.class);
                intent.putExtra("extra_id",rsndm);
                //Log.d("ssss","dsadasdasd");
                startActivity(intent);
            }
        });
        //
        textView=(TextView)findViewById(R.id.introduction);
        nameTextView=(TextView)findViewById(R.id.intro_name);

        //font type
        Typeface face = Typeface.createFromAsset (getAssets() , "kaiti.ttf" );
        textView.setTypeface (face);
        nameTextView.setTypeface(face);

        //数据库操作
        SQLiteDatabase db = DBManager.getNewDatabase();
        Cursor cursor = db.rawQuery("select name,source from cipai where id=" + rsndm, null);

        String source=null;
        String name=null;
        while (cursor.moveToNext()){
            source =cursor.getString(cursor.getColumnIndex("source"));
            name =cursor.getString(cursor.getColumnIndex("name"));
        }



        if(source!=null) {
            textView.setText(source);
        }else textView.setText("             携手共进\n" +
                                 "ci_helper开发组要承担大量的带宽费用\n " +
                                 "数据库找不到也没得办法啊\n " +
                                 "大家可以通过打赏一起参与到ci_helper的开发中");
        nameTextView.setText(name);

        //名字的导入
        //nameTextView=(TextView)findViewById(R.id.intro_name);

    }
}
